package com.gonsin.gnews.annotations.enums;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public enum NewFieldType {


    DOUBLE("double", "浮点型"),
    INT("int", "整形"),
    STRING("String", "字符串"),
    BOOLEAN("boolean", "布尔值"),
    ;

    private String value;

    private String name;

    NewFieldType(String value, String name) {
        this.value = value;
        this.name = name;
    }

    public String getValue() {
        return value;
    }

    public String getName() {
        return name;
    }

    private static Map<String, NewFieldType> map;

    static {
        map = new HashMap<>();
        NewFieldType[] keys = NewFieldType.values();
        for (NewFieldType key : keys) {
            map.put(key.getValue(), key);
        }
    }

    public static NewFieldType get(String value) {
        return map.get(value);
    }

    /**
     * 获取列表
     *
     * @return
     */
    public static List<Map<String, Object>> list() {
        return Arrays.stream(values()).map(a -> {
            Map<String, Object> m = new HashMap<>();
            m.put("value", a.getValue());
            m.put("name", a.getName());
            return m;
        }).collect(Collectors.toList());
    }


}
